package ar.edu.ufasta.presupuestos.servicios.web;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PresupuestoSrv {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM");
		Date fecha = new Date();
		LogFile.setLogFileName(simple.format(fecha)+"_PresupuestoSrv.txt");
		ServerSocket serverSocket = null;
		try {
			// TODO el parametro tomarlo del properties
			serverSocket = new ServerSocket(6060);
			LogFile.write("/ ---- Service Socket Started ---- /");
			//logfile.info("--- Service Socket Started ---");
		}
		catch (IOException e){
			LogFile.write("**** Error on Server Socket Start ****");
			//logfile.severe("*** Error on Server Socket Start ***");
			System.exit(-1);
		}
			
		try {
			while (true) {
				Socket socket = serverSocket.accept();
				ClientConnection cc;
				cc = new ClientConnection(socket);
				cc.start();
				//socket.close();
				
				//logfile.info("--- Remote client connected : " + serverSocket.accept().getInetAddress() + " ---");
				
			}
		} finally {
			serverSocket.close();
			LogFile.write("/ ---- Service Socket Stopped ---- /");
			//logfile.info("--- Service Socket Stopped ---");			
		}
		
	}

}
